﻿using System;
using System.Threading;
using OME;

namespace OME.Storage
{
   [Serializable]
   public abstract class Order
   {
      string trader;
      string instrument;
      string buySell;
      string orderType;
      double price;
      int quantity;
      static long globalOrderId;
      long orderId;
      DateTime orderTimeStamp;

      public Order()
      {
         //Generate Default Values 
         //Global unique order ID
         orderId = Interlocked.Increment(ref globalOrderId);
         //Order Time Stamp
         orderTimeStamp = DateTime.Now;
      }

      public Order(string id, string service, string orderType, string buySell, double price, int quantity)
      {
         this.trader = id;
         this.instrument = service;
         this.orderType = orderType;
         this.buySell = buySell;
         this.price = price;
         this.quantity = quantity;

      }

      public DateTime TimeStamp
      {
         get { return orderTimeStamp; }
      }

      public string TraderID
      {
         get { return trader; }
         set { trader = value; }
      }

      public string Instrument
      {
         get { return instrument; }
         set { instrument = value; }
      }

      public string OrderType
      {
         get { return orderType; }
         set { orderType = value; }
      }

      public string BuySell
      {
         get { return buySell; }
         set { buySell = value; }
      }

      public double Price
      {
         get { return price; }
         set { price = value; }
      }

      public int Quantity
      {
         get { return quantity; }
         set
         {
            if (value < 0)
               quantity = 0;
            else
               quantity = value;
         }
      }

      public long OrderID
      {
         get { return orderId; }
         set { orderId = value; }
      }

      public override string ToString()
      {
         string print = trader + "|" + instrument + "|" + OrderType + "|" + buySell + "|" + quantity.ToString() + "|" + Price.ToString();
         return print;
      }

      public string[] ToStringArray()
      {
         string[] order = new string[6];

         order[0] = this.trader;
         order[1] = this.instrument;
         order[2] = this.OrderType;
         order[3] = this.buySell;
         order[4] = this.quantity.ToString();
         order[5] = this.Price.ToString();


         return order;
      }
   }
}
